package com.zeng.incast.videoplay.filemanager;

import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;

import androidx.appcompat.app.AppCompatActivity;

import com.zeng.incast.videoplay.R;


public class PreviewActivity extends AppCompatActivity {
    private static final String TAG = "Preview";

    private VideoView mVideoView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.preview);

        //String file = "http://192.168.100.128:8080/upload/1.mp4";
        //String file ="/sdcard/1.3gp";
        //String file ="/sdcard/2.mp4";
        String file ="/sdcard/3.mp4";

        mVideoView = (VideoView)this.findViewById(R.id.videoView);
        mVideoView.setMediaController(new MediaController(this));
        mVideoView.setOnCompletionListener(new MyPlayerOnCompletionListener());
        mVideoView.setVideoPath(file);
        mVideoView.start();
    }

    class MyPlayerOnCompletionListener implements MediaPlayer.OnCompletionListener {
        @Override
        public void onCompletion(MediaPlayer mp) {
            Toast.makeText( PreviewActivity.this, "播放完成了", Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        Log.e(TAG, "onDestroy: Preview");
        mVideoView.stopPlayback();
    }
}
